package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.HRecordSalaryInfoDto;
import com.crm.jdy.common.dto.WOutInfoDto;
import com.crm.jdy.common.pojo.HRecordSalaryInfo;
import com.crm.jdy.common.pojo.WOutInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.HRecordSalaryInfoService;
import com.crm.jdy.service.drp.WOutInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 薪资档案表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "hRecordSalaryInfo", description = "薪资档案表信息")
@RestController
@RequestMapping("/hRecordSalaryInfo")
public class HRecordSalaryInfoController{

    @Reference(version = "${service.version}", check = false)
    HRecordSalaryInfoService wOutInfoService;

    @RateLimit()
    @ApiOperation("项目信息")
    @PostMapping("/seleteHRecordSalaryInfo")
    public ResultVo seleteHRecordSalaryInfo(@RequestBody HRecordSalaryInfoDto wOutInfo){
        PageInfo<HRecordSalaryInfo> list = wOutInfoService.seleteHRecordSalaryInfo(wOutInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新项目信息")
    @PostMapping("/updateHRecordSalaryInfo")
    public ResultVo updateHRecordSalaryInfo(@ApiParam(value = "wOutInfo", required = true)
                                   @Validated @RequestBody HRecordSalaryInfo wOutInfo){
        boolean index = wOutInfoService.updateHRecordSalaryInfo(wOutInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加项目信息")
    @PostMapping("/addHRecordSalaryInfo")
    public ResultVo addWOutInfo(@ApiParam(name = "wOutInfo", required = false)
                                @Validated @RequestBody HRecordSalaryInfo wOutInfo){
        boolean list  = wOutInfoService.addHRecordSalaryInfo(wOutInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除项目信息")
    @DeleteMapping("deleteHRecordSalaryInfo/{recId}")
    public ResultVo deleteHRecordSalaryInfo(@NotNull @ApiParam(name = "recId", value = "recId", required = true) @PathVariable String recId){
        boolean b = wOutInfoService.removeHRecordSalaryInfo(recId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}